package com.xiaoshi.exception;

import com.xiaoshi.enums.JsonReturnEnums;
import com.xiaoshi.interfaces.MyHttpServiceCode;
import lombok.Data;

@Data
public class PlatformException extends RuntimeException {

    private Integer status = null;
    private String msg = null;

    private static PlatformException plEx= new PlatformException();

    public PlatformException(String msg) {
        status = MyHttpServiceCode.AMIS_FAIL;
        setMsg(msg);
    }

    public PlatformException() {
    }

    public PlatformException(Integer ecode, String emsg) {
        this.status = ecode;
        this.msg = emsg;
    }


    public PlatformException(JsonReturnEnums jsonReturnCode) {
        super(jsonReturnCode.getDesc());
        this.status = jsonReturnCode.getCode();
        this.msg = jsonReturnCode.getDesc();
    }


    /**
     *
     * @param msg
     * @param formatstr
     * @return
     */
    public static PlatformException platEXformatByCode(Integer ecode,String msg,Object ...formatstr){
        plEx.setStatus( ecode);
        plEx.setMsg(String.format(msg, formatstr) );
        return plEx;
    }

    /**
     *   %s  转换
     * @param msg
     * @param formatstr
     * @return
     */
    public static PlatformException platEXformat(String msg,Object ...formatstr){
        plEx.setStatus( MyHttpServiceCode.AMIS_FAIL);
        plEx.setMsg(String.format(msg, formatstr) );
        return plEx;
    }




    @Override
    public String getMessage() {
        return msg;
    }

}
